package com.example.exercise.feedback.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;

import com.example.exercise.feedback.vo.AppFeedbackReplyVO;
import com.example.exercise.feedback.service.AppFeedbackReplyService;
import com.example.exercise.common.base.BaseResponse;

/**
* 
*/
@RestController
@RequestMapping("/appFeedbackReply")
@Tag(name = "用户反馈回复", description = "用户反馈回复")
public class AppFeedbackReplyController {

    @Autowired
    private AppFeedbackReplyService appFeedbackReplyService;

    @Operation(summary = "分页查询列表", description = "分页查询列表")
    @RequestMapping(value = "findByWhere", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Page<AppFeedbackReplyVO>> findByWhere(@RequestBody AppFeedbackReplyVO appFeedbackReplyVO, Page<AppFeedbackReplyVO> page){
        BaseResponse<Page<AppFeedbackReplyVO>> baseResponse = new BaseResponse<>();
        List<AppFeedbackReplyVO> list = appFeedbackReplyService.findByWhere(page, appFeedbackReplyVO);
        page.setRecords(list);
        baseResponse.ok(page);
        return baseResponse;
    }

    @Operation(summary = "根据id查详情", description = "根据id查详情")
    @RequestMapping(value = "findByKey", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE })
    public BaseResponse<AppFeedbackReplyVO> findByKey(@RequestBody AppFeedbackReplyVO appFeedbackReplyVO){
        BaseResponse<AppFeedbackReplyVO> baseResponse = new BaseResponse<>();
        AppFeedbackReplyVO appFeedbackReplyVO1 = appFeedbackReplyService.findByKey(appFeedbackReplyVO);
        if(appFeedbackReplyVO1 == null){
            baseResponse.errMsg("数据为空");
        }else{
            baseResponse.ok(appFeedbackReplyVO1);
        }
        return baseResponse;
    }

    @Operation(summary = "添加一条记录", description = "添加一条记录")
    @RequestMapping(value = "insertAppFeedbackReply", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE })
    public BaseResponse<Object> insertAppFeedbackReply(@RequestBody AppFeedbackReplyVO appFeedbackReplyVO){
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        int count = appFeedbackReplyService.insert(appFeedbackReplyVO);
        if(count > 0){
            baseResponse.ok();
        }else{
            baseResponse.errMsg("新增数据失败");
        }
        return baseResponse;
    }

    @Operation(summary = "修改一条记录", description = "修改一条记录")
    @RequestMapping(value = "updateAppFeedbackReplyByKey", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE })
    public BaseResponse<Object> updateAppFeedbackReplyByKey(@RequestBody AppFeedbackReplyVO appFeedbackReplyVO){
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        int count = appFeedbackReplyService.updateByKey(appFeedbackReplyVO);
        if(count > 0){
            baseResponse.ok();
        }else{
            baseResponse.errMsg("修改数据失败");
        }
        return baseResponse;
    }

    @Operation(summary = "删除一条记录", description = "删除一条记录")
    @RequestMapping(value = "deleteByKey", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE })
    public BaseResponse<Object> deleteByKey(@RequestBody AppFeedbackReplyVO appFeedbackReplyVO){
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        int count = appFeedbackReplyService.deleteByKey(appFeedbackReplyVO);
        if(count > 0){
            baseResponse.ok();
        }else{
            baseResponse.errMsg("删除数据失败");
        }
        return baseResponse;
    }

}